from ..DeptService import DeptsService
from ...mapper.DeptsMapper import DeptsMapper
from ...dto.Dept import Dept
from fastapi import Depends
import typing as T
from overrides import override
from datetime import datetime


import logging


class _DeptServiceImp(DeptsService):
    def __call__(self, deptsMapper: DeptsMapper):
        self.deptsMapper = deptsMapper
        return self

    @override
    async def list(self):
        result = await self.deptsMapper.list()
        logging.info(f"DeptsServiceImp.list() result: {result}")
        return result

    @override
    async def delete(self, id: int):
        await self.deptsMapper.delete(id)

    @override
    async def save(self, dept: Dept):
        dept.createTime = datetime.now()
        await self.deptsMapper.save(dept)

    @override
    async def getById(self, id: int):
        result = await self.deptsMapper.getById(id)
        logging.info(f"DeptsServiceImp.getById() result: {result}")
        return result

    @override
    async def update(self, dept: Dept):
        dept.updateTime = datetime.now()
        await self.deptsMapper.update(dept)


DeptService = T.Annotated[_DeptServiceImp, Depends(_DeptServiceImp())]
